﻿using BBCore.Application.Admins;
using BBCore.Core.Models.Admins;
using BBCore.Core.Models.BaseModels;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;

namespace BBCore.Server.Components.Pages.Samples
{
    public partial class TempDetails_ControlDetails
    {
      
        [NotNull]
        [Parameter]
        public MenuEntity? Model { get; set; }
        List<ControlDetails>? Items { get; set; }
        private async Task<bool> OnSaveAsync(ControlDetails item, ItemChangedType changedType)
        {

            if (changedType == ItemChangedType.Add)
            {
                // 新增
                if (item.Menu_AuthId == 0)
                {
                    item.Menu_AuthId = Model.Id;
                }
                await ITempService.Add_ControlDetailsAsync(item);
            }
            else
            {
                //更新
                await ITempService.Update_ControlDetailsAsync(item);
            }
            return await Task.FromResult(true);
        }

        private async Task<QueryData<ControlDetails>> OnQueryAsync(QueryPageOptions options)
        {
            int authid = Model.Id;
            IEnumerable<ControlDetails> items = await ITempService.GetControlDetailsListByIdAsync(authid);
            return await Task.FromResult(new QueryData<ControlDetails>()
            {
                Items = items
            });
        }
        private async Task<bool> OnDeleteAsync(IEnumerable<ControlDetails> items)
        {

            await ITempService.Remove_ControlDetailsAsync(items);
            return await Task.FromResult(true);
        }
    }
}
